#!/bin/bash

xset dpms 0 0 0
xset -dpms
xset s off

DN=$(dirname "$0")

mkdir -p "$DN/log/add"
echo 'groups:' $(groups) >> "$DN/log/add/start.log"

#rm ~/.mozilla/firefox/*/sessionstore.{bak,js}
#firefox "$DN/v1.html"
#
#exit 0

while true; do
	if [ -z "$(ps ax | grep java | grep ru.softlogic.app.Main)" ]; then
		CLASSPATH=$DN
		for jar in $(ls $DN/{lib,ext}/*.jar); do
			CLASSPATH=$CLASSPATH:$jar
		done
		java -cp $CLASSPATH -Djava.library.path=$DN/jni -Dterminal.dir=$DN -Xmx256m ru.softlogic.app.Main
		retval="$?"
		if [ "$retval" == "15" ]; then
			break
		elif [ "$retval" == "16" ]; then
			$DN/configure.sh
		elif [ "$retval" == "17" ]; then
			java -cp $CLASSPATH  -Dterminal.dir=$DN ru.softlogic.app.UpdateMain
		else
			sleep 30
		fi
	else
		sleep 30
	fi
done
